<?php 
Header("Content-type: application/gpx+xml");
print '<?xml version="1.0" encoding="UTF-8"?>'; 
?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="YouLoc GPX Export" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
	<name><?php echo $data["track"]["name"]; ?></name>
	<desc><?php echo $data["track"]["description"]; ?></desc>
	<author>
		<name><?php echo $data["track"]["username"]; ?></name>
	</author>
	<time><?php echo $data["track"]["time"]; ?></time>
</metadata>
<trk>
	<name><?php echo $data["track"]["name"]; ?></name>
	<trkseg>
		<?php while ( list($id, $pointdata) = each ($data["coordinates"])): ?>
		<trkpt lat="<?php printf("%.5f",$pointdata["lat"]); ?>" lon="<?php printf("%.5f",$pointdata["lon"]); ?>">
			<ele><?php printf("%.1f",$pointdata["alt"]); ?></ele>
			<speed><?php printf("%.1f",$pointdata["speed"]); ?></speed>
			<time><?php print $pointdata["time_received"]; ?></time>
			<name><?php printf("%d",$id); ?></name>
		</trkpt>
		<?php endwhile; ?>
	</trkseg>
</trk>
</gpx>

